﻿#region

using System;
using System.Drawing;
using System.Windows.Forms;

#endregion

namespace 五分钟计时
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TopMost = false;

            int 倒计时, 字体大小;
            try
            {
                倒计时 = int.Parse(textBox1.Text);
                字体大小 = int.Parse(textBox2.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确数字！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button1);
                timer1.Enabled = true;
                return;
            }
            Settings data = new Settings();
            data.倒计时 = 倒计时;
            data.位置 = Location;
            data.字体大小 = 字体大小;
            data.颜色 = button2.BackColor;
            timer1.Enabled = false;
            Hide();
            Form2 f = new Form2(data);
            f.ShowDialog();
            Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Pinvoke.GetForegroundWindow() == Handle)
                return;

            TopMost = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            ColorDialog cd = new ColorDialog();
            if (cd.ShowDialog() != DialogResult.OK)
            {
                timer1.Enabled = true;
                return;
            }
            if (cd.Color.ToArgb() == -65537)
            {
                MessageBox.Show("与透明色重复请选择其他颜色！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button1);
                timer1.Enabled = true;
                return;
            }
            button2.BackColor = cd.Color;
            timer1.Enabled = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
//            button2.BackColor=Color.FromArgb(254,255,255);
            button2.BackColor = Color.Black;
        }
    }


    [Serializable]
    public class Settings
    {
        public int 倒计时 { get; set; }
        public int 字体大小 { get; set; }
        public Point 位置 { get; set; }
        public Color 颜色 { get; set; }
    }
}